home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1997 August / Walnut Creek CDROM.7z / VOL_400 / 460_01 / YACL0160.ZIP / uidemo / hello3 / main.cxx < prev    next >
Encoding:
C/C++ Source or Header  |  1996-05-19  |  2.8 KB  |  119 lines

  1.  
  2.  
  3. // A second "hello, world" program using YACL
  4.  
  5.  
  6. #include "ui/applic.h"
  7. #include "ui/composit.h"
  8. #include "ui/font.h"
  9. #include "ui/label.h"
  10. #include "ui/stddlg.h"
  11.  
  12.  
  13. // ======================== Class AppWindow ===========================
  14.  
  15. const UI_ViewID ID_BUTTON = 10;
  16. const UI_ViewID ID_LABEL  = 11;
  17.  
  18.  
  19. UI_ViewDescriptor desc[] = {
  20.     {View_PushButton, ID_BUTTON,  75, 80, 225, 50, TRUE, "", 0},
  21.     {View_Label,      ID_LABEL,   20, 50, 335, 20, FALSE, "",  0},
  22.     {View_None, -1, 0, 0, 0, 0, 0, 0}
  23. };
  24.  
  25. class AppWindow: public UI_CompositeVObject {
  26.  
  27. public:
  28.     AppWindow ();
  29.  
  30.     // Override the Composite's virtual method:
  31.     bool HandleChildEvent (const UI_Event& e);
  32.  
  33.     bool WantToQuit();
  34.     
  35. protected:
  36.     short count;
  37. };
  38.  
  39.     
  40. AppWindow::AppWindow()
  41. : UI_CompositeVObject (NULL, desc, FALSE, UI_Rectangle (50, 50, 400, 300)),
  42.   count (5)
  43. {
  44.     Title () = "YACL Font Change Demo";
  45.     (*this)[ID_BUTTON]->Title() =
  46.         "Click here " + CL_String(count) + " times.";
  47. }
  48.  
  49. bool AppWindow::HandleChildEvent (const UI_Event& e)
  50. {
  51.     if (e.Origin()->ViewID() == ID_BUTTON &&
  52.         e.Type() == Event_Select) {
  53.         count--;
  54.         if (count == 0) {
  55.             _Application->Destroy (this);
  56.             // Do an _Application->End() if we want conditional termination
  57.         }
  58.         else {
  59.             (*this)[ID_BUTTON]->Title() =
  60.                 "Click here " + CL_String(count) + " times.";
  61.             switch (count) {
  62.             case 4: {
  63.                 UI_Font& font = Font();
  64.                 font = UI_FontDesc (UIFont_Courier, 14, UIFont_Italic);
  65.                 break;
  66.             }
  67.  
  68.             case 3: {
  69.                 UI_Font& font = e.Origin()->Font();
  70.                 font = UI_FontDesc (UIFont_Times, 14, UIFont_StrikeOut
  71.                                     | UIFont_Italic);
  72.                 break;
  73.             }
  74.                 
  75.             case 2: {
  76.                 UI_Font& font = Font();
  77.                 font = UI_FontDesc (UIFont_Courier, 9, UIFont_BoldFace);
  78.                 break;
  79.             }
  80.  
  81.             case 1: {
  82.                 UI_Font& font = (*this)[ID_LABEL]->Font();
  83.                 font = UI_FontDesc (UIFont_Helvetica, 12, UIFont_Underline);
  84.                 break;
  85.             }
  86.                 
  87.             default:
  88.                 break;
  89.             }
  90.         }
  91.         return TRUE;
  92.     }
  93.     return FALSE;
  94. }
  95.  
  96.  
  97. bool AppWindow::WantToQuit()
  98. {
  99.     return (UI_StandardDialog ("Do you really want to quit?", "Confirm",
  100.                                this, UIS_YesNo, UIS_Question) == UI_IDYES);
  101. }
  102.  
  103.  
  104.  
  105. // ======================== Main program ===========================
  106.  
  107.  
  108. int UI_Application::Main (int , char* [])
  109. {
  110.     UI_CompositeVObject* mainWin = new AppWindow;
  111.     MakeTopWindow (mainWin);
  112.     (*mainWin)[ID_LABEL]->Title() = "Hello, world, this is YACL!";
  113.     Run();
  114.     return 0;
  115. }
  116.  
  117.  
  118.  
  119.